@extends('admin.common.admin')
@section('cnt')
    {{--面包屑导航--}}
    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i>房源管理
        <span class="c-gray en">&gt;</span> 房源列表
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
           href="javascript:location.replace(location.href);" title="刷新">
            <i class="Hui-iconfont">&#xe68f;</i>
        </a>
    </nav>
    <div class="page-container">
        {{--消息提示--}}
        @include('admin.common.msg')
        <div class="text-c">
            <form action="">日期范围：
                <input type="text" value="{{request()->get('datemin')}}" onfocus="WdatePicker()" name="datemin"
                       class="input-text Wdate" style="width:120px;">
                <input type="text" value="{{request()->get('datemax')}}" onfocus="WdatePicker()" name="datemax"
                       class="input-text Wdate" style="width:120px;">
                <input type="text" value="{{request()->get('fang_name')}}" class="input-text" style="width:250px"
                       placeholder="房源名称" id="" name="kw">
                <button type="submit" class="btn btn-success" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜房源
                </button>
            </form>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                {!! $fang->addBtn('admin.fang.create','添加房源') !!}
            </span>
            <span class="r">共有数据：<strong>{{$data->total()}}</strong> 条</span>
        </div>
        <table class="table table-border table-bordered table-bg">
            <thead>
            <tr>
                <th scope="col" colspan="12">用户列表</th>
            </tr>
            <tr class="text-c">
                <th>ID</th>
                <th>房源名称</th>
                <th>小区地址</th>
                <th>租赁方式</th>
                <th>房源业主</th>
                <th>房源租金</th>
                <th>是否推荐</th>
                <th>是否租出</th>
                <th>配套设施</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach($data as $item)
                <tr class="text-c">
                    <td>{{$item->id}}</td>
                    <td>{{$item->fang_name}}</td>
                    <td>{{$item->getAreaToName()}}{{$item->fang_addr}}</td>
                    <td>{{$item->getAttrIdToName($item->fang_rent_class)}}</td>
                    <td>{{$item->owner->name}}</td>
                    <td>￥{{$item->fang_rent}}</td>
                    <td>{!! $item->recommend !!}</td>
                    <td>
                        @if($item->fang_status==0)
                            <span class="label label-success radius">未租出</span>
                        @else
                            <span class="label label-warning radius">已租出</span>
                        @endif
                    </td>
                    <td>{{$item->getAttrIdToName($item->fang_config)}}</td>
                    <td class="td-manage">
                        {!! $item->editBtn('admin.fang.rent','出租',$item)  !!}
                        {!! $item->editBtn('admin.fang.edit','修改',$item) !!}
                        {!! $item->delBtn('admin.fang.destroy','删除',$item) !!}
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
        {{ $data->appends(request()->except('page'))->links() }}
    </div>
@endsection
@section('js')
    <script>
        //删除单个用户
        $('.delbtn').click(function () {
            //询问
            layer.confirm('确定要删除该用户吗？', {
                btn: ['确定', '取消']
            }, () => {
                //发起ajax
                $.ajax({
                    url: $(this).attr('href'),
                    type: 'delete',
                    data: {_token: "{{csrf_token()}}"}
                }).then(res => {
                    layer.msg(res.msg, {icon: 1, time: 1000}, () => {
                        $(this).parents('tr').remove();
                    })
                });
            })
            //阻止默认行为
            return false;
        });

        //删除选中用户
        function datadel() {
            //选中用户id组成的数组
            let id = [];
            //获取选中的checkbox
            let ckeckboxlist = $('input[name="id[]"]:checked');
            if (ckeckboxlist.length > 0) {
                $.each(ckeckboxlist, (key, item) => {
                    id.push(Number($(item).val()));
                });
            }
            if (id.length > 0) {
                //询问
                layer.confirm('确定要删除这些用户吗？', {
                    btn: ['确定', '取消']
                }, () => {
                    $.get('{{route('admin.admin.delAll')}}', {id}).then(res => {
                        layer.msg(res.msg, {ico: 1, time: 1000}, () => {
                            location.reload();
                        })
                    });
                })
            }
        }
    </script>
@endsection